package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPunchDailySummaryAddDTO;
import org.jsola.hr.dto.AttendPunchDailySummaryUpdateDTO;
import org.jsola.hr.entity.AttendPunchDailySummaryDO;
import org.jsola.hr.query.AttendPunchDailySummaryQuery;
import org.jsola.hr.service.IAttendPunchDailySummaryService;
import org.jsola.hr.vo.AttendPunchDailySummaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPunchDailySummaryTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchDailySummaryService attendPunchDailySummaryService;

    /**
     * 生成add测试数据
     * @return AttendPunchDailySummaryAddDTO
     */
    public AttendPunchDailySummaryAddDTO getAttendPunchDailySummaryAddDTO(){
        AttendPunchDailySummaryAddDTO attendPunchDailySummaryAddDTO = new AttendPunchDailySummaryAddDTO();
        attendPunchDailySummaryAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPunchDailySummaryAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPunchDailySummaryAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPunchDailySummaryAddDTO.setAttendPlanName(getRandomValue("varchar",50));
        attendPunchDailySummaryAddDTO.setYearly(getRandomValue("varchar",10));
        attendPunchDailySummaryAddDTO.setMonthly(getRandomValue("varchar",10));
        attendPunchDailySummaryAddDTO.setDaily(getRandomValue("varchar",10));
        attendPunchDailySummaryAddDTO.setSummaryDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        attendPunchDailySummaryAddDTO.setShouldPeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setActualPeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setLatePeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setEarlyPeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setOnWorkMissPeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setOffWorkMissPeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setLeavePeoples(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchDailySummaryAddDTO.setIsUsed(SafeKit.getInteger(getRandomValue("tinyint",0)));
        return attendPunchDailySummaryAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchDailySummaryUpdateDTO
     */
    public AttendPunchDailySummaryUpdateDTO getAttendPunchDailySummaryUpdateDTO(AttendPunchDailySummaryVO attendPunchDailySummaryVO){
        return attendPunchDailySummaryService.selectDOById(attendPunchDailySummaryVO.getId(), SITE_ID).to(AttendPunchDailySummaryUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchDailySummaryQuery
     */
    public AttendPunchDailySummaryQuery getAttendPunchDailySummaryQuery() {
        AttendPunchDailySummaryQuery attendPunchDailySummaryQuery = new AttendPunchDailySummaryQuery();
        List<AttendPunchDailySummaryDO> attendPunchDailySummaryDOList = attendPunchDailySummaryService.list(new AttendPunchDailySummaryDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchDailySummaryDOList)) {
            AttendPunchDailySummaryDO attendPunchDailySummaryDO = attendPunchDailySummaryDOList.get(0);
            attendPunchDailySummaryQuery = attendPunchDailySummaryDO.to(AttendPunchDailySummaryQuery.class);
            if (attendPunchDailySummaryDO.getSummaryDate() != null) {
                attendPunchDailySummaryQuery.setSummaryDateStart(DateKit.getBeforeDay(attendPunchDailySummaryDO.getSummaryDate(),-1));
                attendPunchDailySummaryQuery.setSummaryDateEnd(DateKit.getBeforeDay(attendPunchDailySummaryDO.getSummaryDate(),1));
            }
            if (attendPunchDailySummaryDO.getGmtCreate() != null) {
                attendPunchDailySummaryQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPunchDailySummaryDO.getGmtCreate(),-1));
                attendPunchDailySummaryQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPunchDailySummaryDO.getGmtCreate(),1));
            }
            if (attendPunchDailySummaryDO.getGmtModified() != null) {
                attendPunchDailySummaryQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPunchDailySummaryDO.getGmtModified(),-1));
                attendPunchDailySummaryQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPunchDailySummaryDO.getGmtModified(),1));
            }
        }
        return attendPunchDailySummaryQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchDailySummaryVO
     */
    public AttendPunchDailySummaryVO saveAttendPunchDailySummaryExample(){
        AttendPunchDailySummaryAddDTO addDTO = this.getAttendPunchDailySummaryAddDTO();
        AttendPunchDailySummaryVO attendPunchDailySummaryVO = attendPunchDailySummaryService.save(addDTO,buildTokenUser());
        return attendPunchDailySummaryVO;
    }


}

